package com.example.sharding.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.example.sharding.enerty.TAnnotationDataDict;
import com.example.sharding.enerty.TAnnotationDataItem;
import com.example.sharding.enerty.TAnnotationStudent;
import com.example.sharding.service.TAnnotationDataDictService;
import com.example.sharding.service.TAnnotationDataItemService;
import com.example.sharding.service.TAnnotationStudentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: test_demo
 * @description: 字典测试
 * @author: yanghua
 * @create: 2021-11-04 19:51
 **/
@RestController
@RequestMapping("/dictTest")
public class DictTest {
    @Resource
    private TAnnotationDataDictService tanotationDataDictService;
    @Resource
    private TAnnotationDataItemService tannotationDataItemService;
    @Resource
    private TAnnotationStudentService tannotationStudentService;

    @ApiOperation("等级描述")
    @GetMapping("/addTAnnotationDataDict")
    public void addTAnnotationDataDict(){
        List<TAnnotationDataDict> list = new ArrayList<>();
        TAnnotationDataDict dataDict = new TAnnotationDataDict();
        dataDict.setDatasource("stu_level");
        dataDict.setDescription("学生等级");
        list.add(dataDict);

        TAnnotationDataDict dataDict2 = new TAnnotationDataDict();
        dataDict2.setDatasource("stu_english");
        dataDict2.setDescription("学生英语水平");
        list.add(dataDict2);

        TAnnotationDataDict dataDict3 = new TAnnotationDataDict();
        dataDict3.setDatasource("stu_hobby");
        dataDict3.setDescription("学生爱好");
        list.add(dataDict3);


        tanotationDataDictService.saveBatch(list);
    }
    @ApiOperation("等级的具体划分")
    @GetMapping("/addTAnnotationDataItem")
    public void addTAnnotationDataItem(){
        List<TAnnotationDataItem> list = new ArrayList<>();
        TAnnotationDataItem dataDict00 = new TAnnotationDataItem();
        dataDict00.setDatasource("stu_level");
        dataDict00.setCode("1");
        dataDict00.setVal("A");
        list.add(dataDict00);
        TAnnotationDataItem dataDict01 = new TAnnotationDataItem();
        dataDict01.setDatasource("stu_level");
        dataDict01.setCode("2");
        dataDict01.setVal("B");
        list.add(dataDict01);
        TAnnotationDataItem dataDict02 = new TAnnotationDataItem();
        dataDict02.setDatasource("stu_level");
        dataDict02.setCode("3");
        dataDict02.setVal("C");
        list.add(dataDict02);
        TAnnotationDataItem dataDict03 = new TAnnotationDataItem();
        dataDict03.setDatasource("stu_level");
        dataDict03.setCode("4");
        dataDict03.setVal("D");
        list.add(dataDict03);

        TAnnotationDataItem dataDict20 = new TAnnotationDataItem();
        dataDict20.setDatasource("stu_english");
        dataDict20.setCode("1");
        dataDict20.setVal("优");
        list.add(dataDict20);
        TAnnotationDataItem dataDict21 = new TAnnotationDataItem();
        dataDict21.setDatasource("stu_english");
        dataDict21.setCode("2");
        dataDict21.setVal("良");
        list.add(dataDict21);
        TAnnotationDataItem dataDict22 = new TAnnotationDataItem();
        dataDict22.setDatasource("stu_english");
        dataDict22.setCode("3");
        dataDict22.setVal("差");
        list.add(dataDict22);


        TAnnotationDataItem dataDict30 = new TAnnotationDataItem();
        dataDict30.setDatasource("stu_hobby");
        dataDict30.setCode("1");
        dataDict30.setVal("爱好跑步");
        list.add(dataDict30);
        TAnnotationDataItem dataDict31 = new TAnnotationDataItem();
        dataDict31.setDatasource("stu_hobby");
        dataDict31.setCode("2");
        dataDict31.setVal("爱好睡觉");
        list.add(dataDict31);

        TAnnotationDataItem dataDict32 = new TAnnotationDataItem();
        dataDict32.setDatasource("stu_hobby");
        dataDict32.setCode("3");
        dataDict32.setVal("爱好吃饭");
        list.add(dataDict32);
        TAnnotationDataItem dataDict33 = new TAnnotationDataItem();
        dataDict33.setDatasource("stu_hobby");
        dataDict33.setCode("4");
        dataDict33.setVal("爱好喝水");
        list.add(dataDict33);
        TAnnotationDataItem dataDict34 = new TAnnotationDataItem();
        dataDict34.setDatasource("stu_hobby");
        dataDict34.setCode("5");
        dataDict34.setVal("爱好喝奶");
        list.add(dataDict34);
        TAnnotationDataItem dataDict35 = new TAnnotationDataItem();
        dataDict35.setDatasource("stu_hobby");
        dataDict35.setCode("6");
        dataDict35.setVal("爱好吃苹果");
        list.add(dataDict35);


        tannotationDataItemService.saveBatch(list);
    }
    @ApiOperation("学生信息")
    @PostMapping("/addTAnnotationStudent")
    public void addTAnnotationStudent(@RequestBody List<TAnnotationStudent> list){

//        TAnnotationStudent dataDict00 = new TAnnotationStudent();
//        dataDict00.setName("李华");
//        dataDict00.setStuLevel("1");
//        dataDict00.setEnglishLevel("1");
//        dataDict00.setStuHobby("1,3,4");
//        list.add(dataDict00);
//        TAnnotationStudent dataDict01 = new TAnnotationStudent();
//        dataDict01.setName("武松");
//        dataDict01.setStuLevel("1");
//        dataDict01.setEnglishLevel("2");
//        dataDict01.setStuHobby("2,1,5,6");
//        list.add(dataDict01);
//        TAnnotationStudent dataDict02 = new TAnnotationStudent();
//        dataDict02.setName("武大郎");
//        dataDict02.setStuLevel("2");
//        dataDict02.setEnglishLevel("3");
//        dataDict02.setStuHobby("1,6,4");
//        list.add(dataDict02);
//        TAnnotationStudent dataDict03 = new TAnnotationStudent();
//        dataDict03.setName("西门庆");
//        dataDict03.setStuLevel("3");
//        dataDict03.setEnglishLevel("2");
//        dataDict03.setStuHobby("1,2,3,4,5,6");
//        list.add(dataDict03);

        tannotationStudentService.saveBatch(list);

    }
    @ApiOperation("分页查询学生信息")
    @PostMapping("/listPager")
    public IPage<TAnnotationStudent> listPager(@RequestBody TAnnotationStudent student){
        IPage<TAnnotationStudent> listPager = tannotationStudentService.listPager(student);
        return listPager;
    }
    @ApiOperation("查询学生信息list")
    @PostMapping("/listNoPager")
    public List<TAnnotationStudent> listNoPager(@RequestBody TAnnotationStudent student){
        List<TAnnotationStudent> list = tannotationStudentService.list();
        return list;
    }
    @ApiOperation("查询单个学生信息")
    @PostMapping("/single")
    public R<TAnnotationStudent> single(@RequestBody TAnnotationStudent student){
        R<TAnnotationStudent> list = tannotationStudentService.single(student);
        return list;
    }

}
